1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
use crate::co;
use crate::decl::*;
use crate::msg::*;
use crate::prelude::*;
use crate::user::privs::*;

/// [`EM_GETCUEBANNER`](https://learn.microsoft.com/en-us/windows/win32/controls/em-getcuebanner)
/// message parameters.
///
/// Return type: `SysResult<()>`.
pub struct GetCueBanner<'a> {
	pub buffer: &'a mut WString,
}

unsafe impl<'a> MsgSend for GetCueBanner<'a> {
	type RetType = SysResult<()>;

	fn convert_ret(&self, v: isize) -> Self::RetType {
		match v {
			0 | 1 => Ok(()),
			_ => Err(co::ERROR::BAD_ARGUMENTS),
		}
	}

	fn as_generic_wm(&mut self) -> WndMsg {
		WndMsg {
			msg_id: co::EM::GETCUEBANNER.into(),
			wparam: unsafe { self.buffer.as_mut_ptr() } as _,
			lparam: self.buffer.buf_len() as _,
		}
	}
}

/// [`EM_HIDEBALLOONTIP`](https://learn.microsoft.com/en-us/windows/win32/controls/em-hideballoontip)
/// message, which has no parameters.
///
/// Return type: `SysResult<()>`.
pub struct HideBalloonTip {}

unsafe impl MsgSend for HideBalloonTip {
	type RetType = SysResult<()>;

	fn convert_ret(&self, v: isize) -> Self::RetType {
		zero_as_badargs(v).map(|_| ())
	}

	fn as_generic_wm(&mut self) -> WndMsg {
		WndMsg {
			msg_id: co::EM::HIDEBALLOONTIP.into(),
			wparam: 0,
			lparam: 0,
		}
	}
}

/// [`EM_SETCUEBANNER`](https://learn.microsoft.com/en-us/windows/win32/controls/em-setcuebanner)
/// message parameters..
///
/// Return type: `SysResult<()>`.
pub struct SetCueBanner {
	pub show_even_with_focus: bool,
	pub text: WString,
}

unsafe impl MsgSend for SetCueBanner {
	type RetType = SysResult<()>;

	fn convert_ret(&self, v: isize) -> Self::RetType {
		zero_as_badargs(v).map(|_| ())
	}

	fn as_generic_wm(&mut self) -> WndMsg {
		WndMsg {
			msg_id: co::EM::SETCUEBANNER.into(),
			wparam: self.show_even_with_focus as _,
			lparam: self.text.as_ptr() as _,
		}
	}
}

/// [`EM_SHOWBALLOONTIP`](https://learn.microsoft.com/en-us/windows/win32/controls/em-showballoontip)
/// message parameters.
///
/// Return type: `SysResult<()>`.
pub struct ShowBalloonTip<'a, 'b, 'c> {
	pub info: &'c EDITBALLOONTIP<'a, 'b>,
}

unsafe impl<'a, 'b, 'c> MsgSend for ShowBalloonTip<'a, 'b, 'c> {
	type RetType = SysResult<()>;

	fn convert_ret(&self, v: isize) -> Self::RetType {
		zero_as_badargs(v).map(|_| ())
	}

	fn as_generic_wm(&mut self) -> WndMsg {
		WndMsg {
			msg_id: co::EM::SHOWBALLOONTIP.into(),
			wparam: 0,
			lparam: self.info as *const _ as _,
		}
	}
}